<?php

namespace app\times\controller;

use think\Db;
use think\Log;

/**
 * 费率
 * Class
 * @package
 */
class Rate
{

	use \app\common\traits\ToolTrait;
	/**
	 * 费改 - 定时
	 */
	public function mods_times()
	{
		try {
			$times = time();
			$bign = strtotime(date("Y-m-d") . "12:00:00");
			$ends =  strtotime(date("Y-m-d") . "23:59:59");
			// 当前时间
			if ($bign < $times && $ends > $times) {
				$limit = 10;
				$date = strtotime(date("Y-m-d", time()));
				$table = "equip_rate_mods_times";
				$where = "times = '{$date}'";
				$check = Db::name($table)
					->where($where)
					->count();
				if ($check) {
					$query = Db::name($table)
						->where($where)
						->field("id,ids,times")
						->limit(0, $limit)->select();
					if ($query) {
						foreach ($query as $key => $vals) {
							$res = \app\times\controller\oprate\Feemods::instance()->handle($vals["ids"]);
							if ($res) {
								\app\times\controller\oprate\Feemods::instance()->del_times_cords($vals["id"]);
							}
						}
					}
					echo "运行正常........计算中...........！！！";
				} else {
					echo "暂无计算信息...........！！！";
				}
			} else {
				echo "运行时间[每天]：12:00:00 至 23:59:59...................！！！";
			}
		} catch (\Exception $e) {
			Log::write($e->getMessage());
		}
	}
}
